invite_mod = {
    init: function() {
        tuenti_lib.onchangepage.add(this, false);
    },
    onChangePage: function(response){
        var func = system_lib.url.getParam('func', response.request_object.url);

        if (func != 'view_invite_friends')
            return;

        //añadimos UI
        var div = document.createElement('div');
        div.style.cssFloat = 'right';
        div.style.marginTop = '5px';
        div.innerHTML = '<a id="tplus_invall" href="#">Todos </a>/<a id="tplus_invnone" href="#"> Ninguno</a>';

        var parent = system_lib.select('div#event_invite_friends div.friendsList.go, div#lightbox_invite_friends div.friendsList.go');

        parent[0].insertBefore(div, parent[0].childNodes[0]);

        //enlazamos UI
        var invall = document.getElementById('tplus_invall');
        var invnone = document.getElementById('tplus_invnone');

        invall.addEventListener('click', this._onClickInvAll, false);
        invnone.addEventListener('click', this._onClickInvNone, false);
    },
    _clickAll: function(exp) {
        var list = system_lib.select(exp);

        for (var i = 0; i < list.length; i++)
            system_lib.fireEvent(list[i], 'click');
    },
    _onClickInvAll: function(ev) {

        ev.preventDefault();
        invite_mod._clickAll('div#memberlist_not_invited_friends_list div.item, div#event_not_invited_friends_list div.item');
    },
    _onClickInvNone: function(ev) {
        ev.preventDefault();
        invite_mod._clickAll('div#already_invited_friends_list div.item, div#invited_friends_list div.item');
    }
};

invite_mod.init();